home *** CD-ROM | disk | FTP | other *** search
- #!../blt_wish -f
-
- if [file exists ../library] {
- set blt_library ../library
- }
- set graph .graph
-
- blt_bitmap define pattern1 { {4 4} {01 02 04 08} }
- blt_bitmap define pattern2 { {4 4} {08 04 02 01} }
- blt_bitmap define pattern3 { {2 2} {01 02 } }
- blt_bitmap define pattern4 { {4 4} {0f 00 00 00} }
- blt_bitmap define pattern5 { {4 4} {01 01 01 01} }
- blt_bitmap define pattern6 { {2 2} {01 00 } }
- blt_bitmap define pattern7 { {4 4} {0f 01 01 01} }
- blt_bitmap define pattern8 { {8 8} {ff 00 ff 00 ff 00 ff 00 } }
- blt_bitmap define pattern9 { {4 4} {03 03 0c 0c} }
- blt_bitmap define hobbes { {25 25} {
- 00 00 00 00 00 00 00 00 00 c0 03 00 78 e0 07 00 fc f8 07 00 cc 07 04 00
- 0c f0 0b 00 7c 1c 06 00 38 00 00 00 e0 03 10 00 e0 41 11 00 20 40 11 00
- e0 07 10 00 e0 c1 17 00 10 e0 2f 00 20 e0 6f 00 18 e0 2f 00 20 c6 67 00
- 18 84 2b 00 20 08 64 00 70 f0 13 00 80 01 08 00 00 fe 07 00 00 00 00 00
- 00 00 00 00 }
- }
-
- option add *Blt_htext.font *Times-Bold-R*14*
- option add *graph.xTitle "X Axis Label"
- option add *graph.yTitle "Y Axis Label"
- option add *graph.title "A Simple Barchart"
- option add *graph.xFont *Times-Medium-R*12*
- option add *graph.elemBackground white
- option add *graph.elemRelief raised
-
- set visual [winfo screenvisual .]
- if { $visual != "staticgray" && $visual != "grayscale" } {
- option add *print.background yellow
- option add *quit.background red
- }
-
- blt_htext .header -text \
- {This is an example of the blt_barchart widget. The barchart has
- many components; x and y axis, legend, crosshairs, elements, etc.
- You can configure any component by pressing this %%
- button $blt_htext(widget).config -text button \
- -command "exec [list ../blt_wish -f ./grconf.tcl [winfo name .] $graph &]"\
- -bg green
- $blt_htext(widget) append $blt_htext(widget).config
- %%.
-
- To create a postscript file "bar.ps", press the %%
- button $blt_htext(widget).print -text {Print} -command {
- $graph postscript bar.ps -pagewidth 6.5i -pageheight 9i -landscape true
- }
- $blt_htext(widget) append $blt_htext(widget).print
- %% button.}
-
- blt_barchart $graph -invert true
- $graph xaxis configure -command FormatLabel -descending true
- $graph legend configure -mapped false
-
- blt_htext .footer -text {Hit the %%
- button $blt_htext(widget).quit -text quit -command {destroy .}
- $blt_htext(widget) append $blt_htext(widget).quit
- %% button when you've seen enough.%%
- label $blt_htext(widget).logo -bitmap BLT
- $blt_htext(widget) append $blt_htext(widget).logo -padx 20
- %%}
-
- set names { One Two Three Four Five Six Seven Eight }
- if { $visual == "staticgray" || $visual == "grayscale" } {
- set fgcolors { white white white white white white white white }
- set bgcolors { black black black black black black black black }
- } else {
- set fgcolors { red green blue purple orange brown cyan navy }
- set bgcolors { green blue purple orange brown cyan navy red }
- }
- set numColors [llength $names]
-
- for { set i 0} { $i < $numColors } { incr i } {
- $graph element create [lindex $names $i] \
- -data { $i+1 $i+1 } \
- -fg [lindex $fgcolors $i] \
- -bg [lindex $bgcolors $i] \
- -stipple pattern[expr $i+1] \
- -relief raised \
- -bd 2
- }
-
- $graph element create Nine \
- -ydata { -1.0 -2.0 -3.0 } \
- -xdata { 9 } \
- -fg red \
- -relief sunken -stacked true
- $graph element create Ten \
- -data { 10 2 } \
- -fg seagreen \
- -stipple hobbes \
- -background palegreen
- $graph element create Eleven \
- -data { 11 3.3 } \
- -fg blue
-
- $graph tag create bitmap { 7 0 } -bitmap @bitmaps/sharky.bm -anchor sw -bg {}
-
- pack append . \
- .header { padx 20 pady 10 } \
- .graph {} \
- .footer { padx 20 pady 10 }
-
- wm min . 0 0
- bind $graph <B1-ButtonRelease> { %W crosshairs toggle }
-
- proc TurnOnHairs { graph } {
- bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
- }
- proc TurnOffHairs { graph } {
- bind $graph <Any-Motion> {%W crosshairs configure -position @%x,%y}
- }
-
- bind $graph <Enter> { TurnOnHairs %W }
- bind $graph <Leave> { TurnOffHairs %W }
-
- proc FormatLabel { w value } {
- # Determine the element name from the value
- set displaylist [$w element show]
- set index [expr round($value)-1]
- set name [lindex $displaylist $index]
- if { $name == "" } {
- return $name
- }
- # Return the element label
- set info [$w element configure $name -label]
- return [lindex $info 4]
- }
-